package app;

/********************************************************
 *
 *  Project :  TeamProject
 *  Package :  app
 *  File    :  Ingredient.java
 *  Name    :  Tyler Daines
 *  Date    :  Nov 3, 2013
 *
 ********************************************************/
public class Ingredient
{
	private String DEFAULT_NAME = "default name";
	private Integer in_uniqueID;
	private String name;
	private Float amount;
	private Measurement measurement;
	
	//This creates blank ingredient
	public Ingredient(){
		in_uniqueID = null;
		name = DEFAULT_NAME;
		amount = (float)0;
		measurement = null;
	}
	
	//This creates an ingredient to be sent TO the database	
	public Ingredient(String name, float amount, Measurement measurement){
		setName(name);
		setAmount(amount);
		setMeasurement(measurement);
	}
	
	//This creates an ingredient to be populated BY the database
	public Ingredient(int in_uniqueID, String name, Float amount, Measurement measurement){
		setIn_uniqueID(in_uniqueID);
		setName(name);
		setAmount(amount);
		setMeasurement(measurement);
	}
	
	public int getIn_uniqueID() {
		if(in_uniqueID != null){
			return in_uniqueID;
		}else{
			return -1;
		}
	}
	
	public void setIn_uniqueID(int in_uniqueID){
		this.in_uniqueID = in_uniqueID;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		if(name.equals("")||name == null){
			this.name = DEFAULT_NAME;
		}else{
			this.name = name;
		}
	}
	
	public Float getAmount() {
		if(amount == null){
			return (float)0;
		}else{
			return amount;
		}
	}
	
	public void setAmount(Float amount) {
		this.amount = amount;
	}

	public Measurement getMeasurement(){
		return measurement;
	}
	
	public void setMeasurement(Measurement measurement){
		this.measurement = measurement;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((DEFAULT_NAME == null) ? 0 : DEFAULT_NAME.hashCode());
		result = prime * result + ((amount == null) ? 0 : amount.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Ingredient other = (Ingredient) obj;
		if (DEFAULT_NAME == null) {
			if (other.DEFAULT_NAME != null) {
				return false;
			}
		} else if (!DEFAULT_NAME.equals(other.DEFAULT_NAME)) {
			return false;
		}
		if (amount == null) {
			if (other.amount != null) {
				return false;
			}
		} else if (!amount.equals(other.amount)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}
	
	
	
}
